<template>
    <div class="topbox">
        <div class="toptop">
            <div class="topleft" @click="goback">‹</div>
            <div class="topright">
                <slot name="zhangjie"></slot>
            </div>
        </div>
    </div>    
</template>
<script>
export default {
    name:'top',
    methods:{
        goback(){
            if(this.$route.path == '/bookdetail'){
                let obj = {}
                obj.id = this.$store.state.book.bookid
                obj.zj = this.$store.state.bookdetail.nowzj
                obj.ys = this.$store.state.bookdetail.nowys
                obj.title = this.$store.state.book.booktitle
                if(this.$store.state.book.booklist[0] !== undefined){
                    var pd = 0
                    var nage = 0
                    let arr = this.$store.state.book.booklist
                    for(let i = 0;i<arr.length;i++){
                        if(obj.id == arr[i].id){
                            pd += 1
                            nage = i
                        }
                    }
                    // 没有一样的
                    if(pd == 1){
                        arr[nage].zj = obj.zj
                        arr[nage].ys = obj.ys
                    }else{
                        arr.push(obj)
                    }
                    this.$store.commit('book/changebooklist',arr)
                }else{
                    let arr = []
                    arr.push(obj)
                    this.$store.commit('book/changebooklist',arr)
                }
            }
            this.$router.go(-1)
        }
    }
}
</script>
<style lang="less">
@import '../other/all.less';
.topbox{
    height:50px;
    border-bottom: 1px solid #eee;
    z-index:1001;
    width: 100%;
    background-color: white;
    // border:1px solid black;
    position: fixed;
    top:0px;
    .toptop{
        position: relative;
    }
    .topleft{
        position: absolute;
        top: 0px;
        left:5%;
        font-size: 1rem;
        color:#ccc;
    }
    .topright{
        width: 100%;
        // background-color: red;
        line-height:50px;
        font-size: 0.5rem;
        color:@allcolor5;
        // margin-left:15%;
    }
}
</style>